<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>字符串按要求的字符编码来转换</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.iconv" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">iconv</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.5, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">iconv</span> &mdash; <span class="dc-title">字符串按要求的字符编码来转换</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.iconv-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>iconv</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$in_charset</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$out_charset</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   将字符串 <code class="parameter">str</code> 从 <code class="parameter">in_charset</code> 转换编码到 <code class="parameter">out_charset</code>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.iconv-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">in_charset</code></dt>

     <dd>

      <p class="para">
       输入的字符集。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">out_charset</code></dt>

     <dd>

      <p class="para">
       输出的字符集。
      </p>
      <p class="para">
       如果你在 <code class="parameter">out_charset</code> 后添加了字符串 <em>//TRANSLIT</em>，将启用转写（transliteration）功能。这个意思是，当一个字符不能被目标字符集所表示时，它可以通过一个或多个形似的字符来近似表达。
       如果你添加了字符串 <em>//IGNORE</em>，不能以目标字符集表达的字符将被默默丢弃。
       否则，会导致一个 <strong><code>E_NOTICE</code></strong>并返回 <strong><code>FALSE</code></strong>。
      </p>
      <div class="caution"><strong class="caution">Caution</strong>
       <p class="para">
        <em>//TRANSLIT</em> 运行细节高度依赖于系统的  iconv() 实现（参见 <strong><code>ICONV_IMPL</code></strong>）。
        据悉，某些系统上的实现会直接忽略 <em>//TRANSLIT</em>，所以转换也有可能失败，<code class="parameter">out_charset</code> 会是不合格的。
       </p>
      </div>
     </dd>

    
    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       要转换的字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.iconv-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回转换后的字符串， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.iconv-changelog">
   <h3 class="title">更新日志</h3>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>5.4.0</td>
        <td>
         这个版本起，字符非法时候会返回  <strong><code>FALSE</code></strong>，除非在输出字符里指定了 <em>//IGNORE</em> 。
         在之前版本，它会返回一部分字符串。
        </td>
       </tr>

    </tbody>
   
  </table>

 </p>
</div>


 <div class="refsect1 examples" id="refsect1-function.iconv-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2894">
    <p><strong>Example #1 <span class="function"><strong>iconv()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;the&nbsp;Euro&nbsp;symbol&nbsp;'€'."</span><span style="color: #007700">;<br /><br />echo&nbsp;</span><span style="color: #DD0000">'Original&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'TRANSLIT&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ISO-8859-1//TRANSLIT"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'IGNORE&nbsp;&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ISO-8859-1//IGNORE"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'Plain&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ISO-8859-1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Original : This is the Euro symbol &#039;€&#039;.
TRANSLIT : This is the Euro symbol &#039;EUR&#039;.
IGNORE   : This is the Euro symbol &#039;&#039;.
Plain    :
Notice: iconv(): Detected an illegal character in input string in .\iconv-example.php on line 7
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div></div></div></body></html>